package com.webchat.ugc.service.mall;


import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.exception.BusinessException;
import com.webchat.domain.vo.response.mall.MallSPUDetailVO;
import com.webchat.rmi.pgc.mall.MallProductClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import java.util.Map;

@Service
public class MallProductService {


    @Autowired
    private MallProductClient mallProductClient;


    /**
     * 查询商品信息
     *
     * @param productId
     * @return
     */
    public MallSPUDetailVO productInfo(Long productId) {

        // RPC 请求商品服务（webchat-pgc）
        APIResponseBean<MallSPUDetailVO> response = mallProductClient.detail(productId, null);
        if (APIResponseBeanUtil.isOk(response)) {
            return response.getData();
        }
        // TODO
        throw new BusinessException("商品信息查询失败");
    }

    /**
     * 根据sku查询商品信息
     *
     * @param skuId
     * @return
     */
    public MallSPUDetailVO productInfoBySku(Long skuId) {
        // RPC 请求商品服务（webchat-pgc）
        APIResponseBean<MallSPUDetailVO> response = mallProductClient.detailBySku(skuId);
        if (APIResponseBeanUtil.isOk(response)) {
            return response.getData();
        }
        // TODO
        throw new BusinessException("商品信息查询失败");
    }

    /**
     * 根据sku批量查询商品数据
     *
     * @param skuIdList
     * @return
     */
    public Map<Long, MallSPUDetailVO> batchGetProductMap(List<Long> skuIdList) {
        APIResponseBean<Map<Long, MallSPUDetailVO>> responseBean = mallProductClient.batchGetBySku(skuIdList);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new BusinessException("商品信息查询失败");
    }


    /**
     * 批量查询sku对应店铺id
     *
     * @param skuIdList
     * @return
     */
    public Map<Long, Long> batchGetSkuShopIdMap(List<Long> skuIdList) {
        APIResponseBean<Map<Long, Long>> responseBean = mallProductClient.batchGetSkuShopId(skuIdList);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new BusinessException("店铺信息查询失败");
    }

}
